import {useUserInfoStore} from "../../stores/modules/userInfo";
import {useCommonInfoStore} from "../../stores/modules/commonInfo";
import {ref, onMounted} from "vue";
import {onLoad, onPageScroll, onShow} from "@dcloudio/uni-app";
import {
    carRedAPI,
    getBindPidAPI,
    getNavUserAPI,
    getUserInfoAPI,
    giveMemberAPI,
    updateConfigAPI
} from "../../services/me";
import {getBannerListAPI, getNoticeAPI, getNoticeListAPI} from "../../services";
import {toAppletPage, toMiniAppBusiness, toMiniAppOrderPage, toMiniAppRedPage} from "../../utils/utils";
import {BaseImgUrl} from "../../utils/lshttp";
import {getOrderGFListsAPI, getOrderListsAPI, submitOrderAPI, uploadOrderIdAPI} from "../../services/order";

import {getCheckChallengeAPI, userJoinChallengeAPI} from "../../services/lstz";
import {codeBindAPI, getMyMembersAPI} from "../../services/makeMoney";
import {bindWeChatPhoneAPI} from "../../services/login";

export const useMe = () => {
    // 创建一个选择器查询对象，用于后续的DOM操作
    const query = uni.createSelectorQuery();
    // header_box的高度
    const headerBoxHeight = ref(0)
    // 用户储存信息
    const userInfoStore = useUserInfoStore()
    const newUser = ref('新用户') // 是否是新用户
    // 公共储存信息
    const commonInfoStore = useCommonInfoStore()
    // 用户信息
    const user = ref()
    // 会员等级style
    const memberStyle = ref()
    // 菜单信息
    const navMenu = ref([])
    const isShowBindPhone = ref( false) // 是否显示绑定手机号
    // 手机平台
    const platform = uni.getSystemInfoSync().platform;
    // 海报
    const banners = ref([])
    // 首单补贴banner
    const firstOrderBanner = ref([])
    const toRaffle = () => {
        uni.navigateTo({url: '/pages_raffle/index_raffle'})
    }
    // 获取小程序右侧胶囊宽度
    const menuRightWidth = ref()
    // 系统消息变量
    const msgList = ref([])
    // 中间导航栏
    const navList = ref([
        {
            id: 1,
            name: '领食挑战赛',
            isTab: false,
            icon: '/me/me_nav_icon01.png',
            path: '/pages/index/toweburl?url=' + "https://test.lszbg.cn/#/challenge/challenge"
        },
        {
            id: 2,
            name: '福利中心',
            isTab: true,
            icon: '/me/me_nav_icon02.png',
            path: '/pages/fuli/fuli'
        },
        {
            id: 3,
            name: '每日签到',
            isTab: false,
            icon: '/me/me_nav_icon03.png',
            path: '/pages/signin/signin'
        },
        {
            id: 4,
            name: '天天领红包',
            isTab: false,
            icon: '/me/me_nav_icon04.png',
            path: '/pages_gold/mt_redbag'
        },
        {
            id: 5,
            name: '免费领会员',
            isTab: false,
            icon: '/me/me_nav_icon05.png',
            path: '/pagesme/vip/vip'
        }
    ])
    // 我的订单tab
    const orderTabList = ref([
        {
            id: 1,
            name: '待上传',
            count: 0,
            current: 1,
            icon: '/me/me_order_icon01.png',
            path: '/pages_order/me_order'
        },
        {
            id: 2,
            name: '审核中',
            count: 0,
            current: 1,
            icon: '/me/me_order_icon02.png',
            path: '/pages_order/me_order'
        },
        {
            id: 3,
            name: '已驳回',
            count: 0,
            current: 1,
            icon: '/me/me_order_icon03.png',
            path: '/pages_order/me_order'
        },
        {
            id: 4,
            name: '已取消',
            count: 0,
            current: 3,
            icon: '/me/me_order_icon04.png',
            path: '/pages_order/me_order'
        },
        {
            id: 5,
            name: '已完成',
            count: 0,
            current: 2,
            icon: '/me/me_order_icon05.png',
            path: '/pages_order/me_order'
        }
    ])
    // 我的订单数据
    const orderProgressLists = ref([])
    // 入团弹窗是否显示
    const isShowjoinLeague = ref( false)
    // 邀请码
    const temCode = ref()
    onLoad(async (options) => {
        console.log('执行页面加载。。。')

    })

    onShow(async () => {
        console.log('执行页面显示。。。')
        // 获取小程序右侧胶囊宽度
        /* #ifdef MP */
        menuRightWidth.value = uni.getMenuButtonBoundingClientRect().left
        /* #endif */
        // console.log('用户信息', user.value)
        // 页面加载判断用户是否登录和是否新用户
        if (userInfoStore.isNewUser || !userInfoStore.isLoginBool()) {
            newUser.value = '新用户'
            console.log('新用户=', newUser.value)
        } else {
            newUser.value = '老用户'
            console.log('老用户=', newUser.value)
        }

        // 获取海报
        await getNavUser()

        // #ifdef APP-PLUS
        if (platform === 'ios') {
            // 如果是IOS设置是否打开钱包
            plus.runtime.getProperty(plus.runtime.appid, async (appInfo) => {
                // 获取审核版本号
                const {result} = await updateConfigAPI()
                userInfoStore.setIsOpenWXLogin(result.ios_version_config.audit !== parseInt(appInfo.versionCode))
            })
        } else if (platform === 'android') {
            // Android不需要关闭钱包
            userInfoStore.setIsOpenWXLogin(true)
        }
        // #endif

        // #ifdef MP || H5
        // H5不需要关闭钱包
        userInfoStore.setIsOpenWXLogin(true)
        // #endif

        // 系统消息
        msgList.value = []
        const res = await getNoticeListAPI()
        res.result.forEach(item => {
            if (item.is_read === 0){
                msgList.value.push(item)
            }
        })
        // console.log('系统消息', msgList.value)
        // msgList.value = res.result
        if (userInfoStore.isLoginBool()) {
            // 登录后获取用户信息
            await getUserInfo()
            // 获取header_box的高度
            // #ifdef APP-PLUS || MP
            query.select(".top_box_content").boundingClientRect((data) => {
                headerBoxHeight.value = data.height
                console.log('当前位置高度=', data.height)
            }).exec()
            // #endif
            // #ifdef H5
            query.select(".top_box_content").boundingClientRect((data) => {
                headerBoxHeight.value = data.height - 20
                console.log('当前位置高度=', data.height)
            }).exec()
            // #endif
            // 是否绑定手机号
            console.log('是否绑定手机号', userInfoStore.userInfo.username)
            if (!userInfoStore.userInfo.username) {
                isShowBindPhone.value = true
                /* uni.showModal({
                    title: '绑定手机号-提示',
                    content: '您还未绑定手机号，手机号用于抢单、订单核验，和订单状态通知，是否去绑定？',
                    confirmText: '去绑定',
                    success: async function (res) {
                        if (res.confirm) {
                            await uni.navigateTo({
                                url: "/pagesme/settinginfo"
                            })
                        }
                    }
                }) */
            }
            // 页面刷新获取订单数据方法
            await getOrderData()
            // 获取团员数据方法
            await getMyMembers()
            // 获取挑战赛数据方法，数据为空会报错，
            await getChallengeData()
            // 获取红包数据事件
            await getRedBagData()

        } else {
            console.log('未登录')
            user.value = undefined
            // #ifdef APP-PLUS || MP
            query.select(".top_box_content").boundingClientRect((data) => {
                headerBoxHeight.value = data.height
                console.log('当前位置高度=', data.height)
            }).exec()
            // #endif
            // #ifdef H5
            query.select(".top_box_content").boundingClientRect((data) => {
                headerBoxHeight.value = data.height - 20
                console.log('当前位置高度=', data.height)
            }).exec()
            // #endif
            return
        }


    })
    onMounted(() => {
        uni.$on('isSuccess', (params) => {
            console.log('isSuccess', params)
            // isShowBindPhone.value = params
        })
    })
    // 查看会员
    const toVip = () => {
        if (userInfoStore.isLogin()) {
            uni.navigateTo({url: '/pagesme/vip/vip'})
        }
    }
    // 跳转页
    const toIndex = () => {
        if (userInfoStore.isLogin()) {
            uni.switchTab({url: '/pages/index/index'})
        }
    }
    // 获取用户信息具体实现
    const getUserInfo = async () => {
        const res = await getUserInfoAPI()

        user.value = res.result
        console.log('用户信息', user.value)
        // 设置会员等级style
        user.value.is_member === 0 ? setLevelStyle(0) : setLevelStyle(user.value.level.level)
        // console.log('会员等级样式=', memberStyle.value)
        userInfoStore.setUserInfo(user.value)
        // 设置推荐人
        if (commonInfoStore.parentId && !user.value.parent_id) {
            await getBindPidAPI(commonInfoStore.parentId)
        }
    }
    // 设置会员等级style
    const setLevelStyle = (level) => {
        console.log('level=', level)
        level = level === null || level === '' ? 0 : level
        if (level === 1){
            memberStyle.value = {
                background: 'linear-gradient( 180deg, #FFE5C4 0%, #FFF3E5 97%)',
                sjxColor: '#ECB996',
                liveImg: '/me/me_vip1.png',
                liveColor: '#B56D18',
                textColor: '#8F5A1A',
                btnColor: '#AC680B',
                btnBack: 'linear-gradient( 270deg, #FABD66 0%, #FFD495 100%)',
                progressActive: 'linear-gradient( 99deg, #FFC876 0%, #E8A444 99%)',
                progressBack: '#FFFAF6',
            }
        }else if (level === 2){
            memberStyle.value = {
                background: 'linear-gradient( 180deg, #BBDFFF 0%, #DBEDFF 97%)',
                sjxColor: '#86A5C2',
                liveImg: '/me/me_vip2.png',
                liveColor: '#1B4673',
                textColor: '#2B5C85',
                btnColor: '#FFFFFF',
                btnBack: 'linear-gradient( 270deg, #65C0F9 0%, #3AA2FB 100%)',
                progressActive: 'linear-gradient( 270deg, #A6BAD7 0%, #46688F 100%)',
                progressBack: '#FFFFFF',
            }
        }else if (level === 3){
            memberStyle.value = {
                background: 'linear-gradient( 180deg, #FFDC94 0%, #FFE7CA 97%)',
                sjxColor: '#D9B05B',
                liveImg: '/me/me_vip3.png',
                liveColor: '#5B2B09',
                textColor: '#633410',
                btnColor: '#6B3D1A',
                btnBack: 'linear-gradient( 270deg, #FFB231 0%, #FFC86C 100%)',
                progressActive: 'linear-gradient( 99deg, #E8AB48 0%, #D08510 99%)',
                progressBack: '#FFFBF5',
            }
        }else if (level === 4){
            memberStyle.value = {
                background: 'linear-gradient( 180deg, #ECB3F0 0%, #EECEF4 97%)',
                sjxColor: '#CC7ED3',
                liveImg: '/me/me_vip4.png',
                liveColor: '#923A92',
                textColor: '#933D93',
                btnColor: '#FFFFFF',
                btnBack: 'linear-gradient( 270deg, #DF8FDF 0%, #B468BA 100%)',
                progressActive: 'linear-gradient( 99deg, #D67ED6 0%, #A74CA7 100%)',
                progressBack: '#FEF6FF',
            }
        }else if (level === 5){
            memberStyle.value = {
                background: 'linear-gradient( 180deg, #4E4E50 0%, #626263 100%)',
                sjxColor: '#444444',
                liveImg: '/me/me_vip5.png',
                liveColor: '#FFF385',
                textColor: '#FFF385',
                btnColor: '/me/me_level_img05.png',
                btnBack: '/me/me_level_img05.png',
                progressBack: '',
            }
        }else if (level === 0){
            memberStyle.value = {
                background: 'linear-gradient( 180deg, #E2E2E1 0%, #F6F6F6 99%)',
                sjxColor: '#C5C5C5',
                liveImg: '/me/me_vip0.png',
                liveColor: '#333333',
                textColor: '#666666',
                btnColor: '#FFFFFF',
                btnBack: 'linear-gradient( 270deg, #FF7F14 0%, #FF5429 100%)',
                progressActive: '',
                progressBack: '',
            }
        }
    }
    // 获取菜单和Banner
    const getNavUser = async () => {
        const res = await getNavUserAPI()
        navMenu.value = res.result[0].menu
        navList.value = res.result[1].menu
        const resBanner = await getBannerListAPI({banner_type: 3})
        banners.value = resBanner.result
        // 首单补贴banner
        const resFirstOrderBanner = await getBannerListAPI({banner_type: 7})
        console.log('新用户=====',newUser.value)
        if(newUser.value == '新用户'){
            firstOrderBanner.value = resFirstOrderBanner.result
        }else{
            firstOrderBanner.value = []
        }
		console.log("菜单=",resFirstOrderBanner.result);
    }

    // 获取跳转
    const pageUrl = (url, isTab) => {
        if (userInfoStore.isLogin()) {
            if (isTab) {
                uni.switchTab({url})
                return
            }
            uni.navigateTo({url})
        }
    }

    // 跳转登录页面
    const user_login = () => {
        console.log("user_login1")
        const userInfoStore = useUserInfoStore()
        if(!userInfoStore.isOpenWXLogin){
            console.log("user_login2")
            uni.navigateTo({
                url: '/pages/login/phone_login'
            });
            return
        }
        console.log("user_login3")
        uni.navigateTo({
            url: '/pages/login/login'
        });
    }

    // 跳转设置页面
    const handleUpdateAvatar = () => {
        console.log("userInfoStore.isLogin()", userInfoStore.isLogin())
        if (userInfoStore.isLogin()) {
            uni.navigateTo({
                url: '/pages/setting/setting'
            })
        }
    }

    // 绑定手机号
    const handleBindPhone = () => {
        if (userInfoStore.isLogin()) {
            uni.navigateTo({
                url: "/pagesme/settinginfo"
            })
        }
    }
    // vip图标
    const vipIcon = [BaseImgUrl + "/vip/my_vn.png", BaseImgUrl + "/vip/my_vn1.png", BaseImgUrl + "/vip/my_vn2.png", BaseImgUrl + "/vip/my_vn3.png", BaseImgUrl + "/vip/my_vn4.png", BaseImgUrl + "/vip/my_vn5.png"]
    const toBusinessOrder = () => {
        uni.navigateTo({url: '/pages/business_order/order_list?shopId=MTQ0MjIx'})
    }

    // 页面跳转
    const pageNavUrl = (e) => {
        if (!userInfoStore.isLogin()) {
            return
        }
        console.log('item数据=', e)
        let item = e.currentTarget.dataset.url
        if (item.type === 1) {
            // 跳转内置页面
            if (item.name === "商家入驻") {
                uni.navigateTo({
                    url: "/pagesme/businessinto/businessinto"
                })
            } else if (item.name === "新手指南") {
                uni.navigateTo({
                    url: "/pages/index/novice"
                })
            } else if (item.name === "商务合作") {
                uni.navigateTo({
                    url: "/pagesme/businessinto/callus"
                })
            } else if (item.name === "建议反馈") {
                uni.navigateTo({
                    url: "/pagesme/feedback/addfeedback"
                })
            } else if (item.name === "立即入团") {
                isShowjoinLeague.value = true
            } else {
                uni.navigateTo({
                    url: item.path
                })
            }
        }
        if (item.type === 2) {
            // 跳转内置底部菜单
            uni.switchTab({
                url: item.path
            })
        }
        if (item.type === 3) {
            uni.navigateTo({
                url: '/pagesme/me-webview?url=' + item.path
            })
        }
        if (item.type === 4) {
            toMiniAppRedPage(item)
        }
    }
    // 页面跳转美团h5
    const gotuMeituanPage = async (item) => {
        uni.navigateTo({
            url: "/pages/me/meituan-weburl"
        })
    }
    // 绑定手机号，领取会员
    const goToBindPhone = async () => {
        isShowBindPhone.value = false
        await uni.navigateTo({
            url: "/pagesme/settinginfo"
        })
    }
    // 微信授权绑定手机号码
    const getPhoneNumber = async (e) => {
        console.log('用户信息==',e.detail)
        let res = await bindWeChatPhoneAPI(e.detail.code)
        if (res.result){
            console.log('绑定手机成功==',res)
            uni.showToast( {
                title: res.msg,
                icon: 'success',
                duration: 1500,
            })
            const resG = await giveMemberAPI()
            await uni.showToast({
                title: resG.msg,
                icon: 'none'
            })
            setTimeout(function () {
                isShowBindPhone.value = false
                uni.reLaunch( {
                    url: '/pages/me/me'
                })
            }, 1500)

        }
    }
    // 消息通知
    const toMsg = () => {
        uni.navigateTo({
            url: "/pages/index/message"
        })
    }
    // 跳转中间导航页面
    const goToPage = (item, isTab) => {
        if (!userInfoStore.isLogin()) {
            return
        }
        if (isTab){
            uni.switchTab({
                url: item.path
            })
        } else {
            // #ifdef H5
            const commonInfoStore = useCommonInfoStore()
            const city = commonInfoStore.addressDel.city
            uni.navigateTo({url: '/challenge/challenge?city=' + city})
            // #endif
            // #ifdef APP-PLUS || MP
            uni.navigateTo({
                // 正式服
                // url: item.path
                // 测试服
                url: item.path
                // 不使用H5的情况下内部页面跳转
                // url: '/pages/makemoney/getmaker'
            })

            // #endif
            /* uni.navigateTo({
                url: item.path
            }) */
        }
    }

    // goGFShop, // 跳转美团官返店铺
    const goGFShop = async (type, path) => {
        await toMiniAppBusiness(type, path)
    }
    // 跳转美团官返评价goGFPj
    const mtOrderUrl = 'pages/orders/orders'
    const mtAppId = 'gh_72a4eb2d4324'
    const goGFPj = async () => {
        await toAppletPage(1, 1)
    }
    // 上传凭证事件
    // 获取设备信息
    let deviceInfo = uni.getSystemInfoSync().uniPlatform
    const goToOrderCheckFun = async (item) => {
        console.log("item", item)
        // 霸王餐已提交订单号，待上传凭证
        let order = "order"
        if (deviceInfo == 'app'){
            uni.navigateTo( {
                url: "/pages_order/order_app_voucher?orderID=" + item.id + "&source=order"
            })
        } else {
            uni.navigateTo( {
                url: "/pages_order/order_voucher?orderID=" + item.id + "&source=order"
            })
        }
    }
    // 提交审核
    const handleUploadOrderNo = async (id) => {
        const res = await submitOrderAPI({order_id: id})
        if (res.code == 200){
            await uni.showToast({
                title: res.msg,
                icon: 'none',
                duration: 1500,
            })
            getOrderData()
        }
    }
    // 挑战赛数据
    const challengeList = ref([])
    const getChallengeData = async () => {
        const city = commonInfoStore.addressDel.city
        await userJoinChallengeAPI(1, 1, 30, userInfoStore?.userInfo?.id, city).then(res => {
            res.result.forEach( item => {
                // res.result.invite_num = 3 // 测试用，记得注释
                item.arrNum = []
                // item.end_time  = item.end_date.split(' ')[0];
                if (item.type === 1){
                    for (let i = 1; i <= item.order_num; i++){
                        if (i <= item.nums){
                            item.arrNum.push({
                                num: i,
                                name:"第" + Number(i) + "天",
                                current: true
                            })
                        } else {
                            item.arrNum.push({
                                num: i,
                                name:"第" + Number(i) + "天",
                                current: false
                            })
                        }
                    }
                }else {
                    for (let i = 1; i <= item.invite_num; i++){
                        if (i <= item.nums){
                            item.arrNum.push({
                                num: i,
                                name:"第" + Number(i) + "个",
                                current: true
                            })
                        } else {
                            item.arrNum.push({
                                num: i,
                                name:"第" + Number(i) + "个",
                                current: false
                            })
                        }
                    }
                }

            })
            console.log('挑战赛数据====', res.result)
            challengeList.value = res.result
            console.log('挑战赛数据=', challengeList.value)
        }).catch( err => {
            uni.showToast( {
                title: err.msg,
                icon: 'none',
                duration: 1500,
            })
        })

    }
    // 获取已完成订单数据
    // 菜单状态
    const status = ref(1)
    const getOrderData = () => {
        getOrderGFListsAPI({
            status: status.value - 1 + '',
            page: 1,
            limit: 10,
        }).then(res => {
            console.log('进行中订单=',  res.result)
            let pendingUploadArr = []
            let pendingReviewArr = []
            let rejectedArr = []
            orderProgressLists.value = res.result
            res.result.forEach(item => {
                if (item.status === 0 && item.is_cancel === 0 && item.check_status > 0){
                    pendingUploadArr.push(item)
                } else if(item.status === 1 && item.is_cancel === 0 && item.check_status > 0){
                    pendingReviewArr.push(item)
                } else if(item.status === 2 || item.status === 3){
                    rejectedArr.push(item)
                }
            })
            // 待上传订单数量
            orderTabList.value[0].count = pendingUploadArr.length
            // 待审核订单数量
            orderTabList.value[1].count = pendingReviewArr.length
            // 已驳回订单数量
            orderTabList.value[2].count = rejectedArr.length
        }).catch((err) => {
            uni.showToast( {
                title: err.msg,
                icon: 'none',
                duration: 2000
            })
        })
    }
    // 挑战赛倒计时
    const challengeCountdown = (item) => {
        let now = +new Date()
        let putTime = +new Date(item.end_date)
        return (putTime - now)
    }
    //点餐并且保存了订单号时显示上传凭证的倒计时
    const findcountdown = (item) => {
        let nowTime = +new Date()
        let putTime = +new Date(item.end_time)
        return (putTime - nowTime)
    }
    // 抢单未上传订单号倒计时30分钟
    const findcountdownThere = (item) => {
        let nowTime = +new Date();
        let putTime = +new Date(item.end_time.replace(/-/g, "/"));
        return (putTime - nowTime)
    }
    // 提现
    const cashOutFun = () => {
        uni.navigateTo({
            url: "/pages/cashout/cashout"
        })
    }
    // 获取团员数据
    const memberLists = ref([])
    const getMyMembers = async () => {
        const res = await getMyMembersAPI()
        console.log('团员数据=', res.result)
        memberLists.value = res.result
    }
    // 跳转订单页面
    const goToOrderPageFun = (item) => {
        console.log('跳转订单页面=', item)
        uni.navigateTo( {
            url: '/pages_order/me_order?current=' + item.current
        })
    }

    // 获取红包列表数据
    const redBagLists = ref([])
    const getRedBagData = async () => {
        await carRedAPI({
            type: 2,
            status: 0,
            limit: 30,
            page: 1
        }).then(res => {
            console.log('红包列表数据=', res.result.list)
            redBagLists.value = res.result.list
        }).catch(err => {
            uni.showToast( {
                title: err.msg,
                icon: 'none',
            })
        })
    }
    // 监听页面滚动
    const scHeight = ref(0)
    onPageScroll((e) => {
        console.log("scHeight=", e)
        scHeight.value = e.scrollTop

    })

    // 提交邀请码
    const submitTemCode = async () => {
        if (temCode.value.length === 0) {
            await uni.showToast(
                {title: "请输入邀请码", icon: "none"})
            return
        }
        // uni.showToast({title:temCode.value.indexOf('[') + ""})
        if (temCode.value.length > 8 && temCode.value.indexOf('[') !== -1 && temCode.value.indexOf(']') !== -1) {
            temCode.value = temCode.value.split('[')[1]
            temCode.value = temCode.value.split(']')[0]
        }
        await codeBindAPI(temCode.value)
        await uni.showToast({title: "绑定成功", icon: "none"})
    }

    const isShowOrderNum = ref( false) // 是否显示复制订单号弹窗
    const orderNoItem = ref()// 订单号item
    const orderNoVal = ref('') // 订单号
    // 提交订单号item
    const updateOrderNo = async (item) => {
        // 显示订单号弹窗
        isShowOrderNum.value = true
        // 赋值订单号item
        orderNoItem.value = item
    }
    // 提交订单号到后台
    const submitOrderNum = async (res) => {
        console.log('订单信息=', res, orderNoVal.value)
        // 判断平台订单号的位数是否正确
        if (res.shop.type == 1 || res.shop.type == 2){
            // 清除订单号空格
            if (orderNoVal.value.indexOf(' ') != -1) {
                orderNoVal.value = orderNoVal.value.replace(/\s*/g, '')
            }
            // 美团和饿了么订单号
            if (orderNoVal.value.length < 18 || orderNoVal.value.length > 20){
                uni.showToast( {
                    title: '请输入18-20位外卖订单号',
                    icon: 'none',
                    duration: 1500
                })
                return
            }
        } else if (res.shop.type == 3) {
            // 清除订单号空格
            if (orderNoVal.value.indexOf(' ') != -1) {
                orderNoVal.value = orderNoVal.value.replace(/\s*/g, '')
            }
            // 京东订单号
            if (orderNoVal.value.length < 12 || orderNoVal.value.length > 14){
                uni.showToast( {
                    title: '请输入12-14位外卖订单号',
                    icon: 'none',
                    duration: 1500
                })
                return
            }
            console.log('orderNoVal.value==',orderNoVal.value)
        }
        await uploadOrderIdAPI(res.id, orderNoVal.value).then(res => {
            // 隐藏订单号弹窗
            isShowOrderNum.value = false
            uni.showToast( {
                title: "提示："+res.msg,
                icon: 'none',
                duration: 3000
            });
            setTimeout(() => {
              uni.reLaunch({
                  url: '/pages/me/me'
              })
            }, 2000)
        }).catch(err => {
            uni.showToast( {
                title: err.msg,
                icon: 'none',
                duration: 1500
            })
        })
    }
    // 复制订单号
    const orderNoCopy = async (type) => {
        await toMiniAppOrderPage(type)
    }
    //

    return{
        headerBoxHeight, // header_box高度
        user,
        newUser, // 新用户
        mtAppId, // 小程序id
        mtOrderUrl, // 小程序订单页面
        // vipIcon,
        memberStyle, //会员等级style
        banners,
        firstOrderBanner, // 首单补贴banner
        navMenu,
        platform,
        userInfoStore,
        commonInfoStore,
        isShowBindPhone, // 是否显示绑定手机号
        isShowOrderNum, // 是否显示复制订单号弹窗
        orderNoItem, // 订单号item
        orderNoVal, // 订单号
        menuRightWidth, // 右侧胶囊宽度
        msgList, // 系统消息
        navList, // 中间导航菜单
        orderTabList, // 我的订单tab
        orderProgressLists, // 进行中订单数据
        challengeList, // 挑战赛数据列表
        memberLists, // 获取团员数据列表
        scHeight, // 页面滚动高度
        redBagLists, // 红包列表数据
        isShowjoinLeague,// 入团弹窗
        temCode, // 邀请码
        user_login,
        pageUrl,
        toVip, // 查看会员
        toIndex, // 去首页下单，开通会员，升级会员
        handleUpdateAvatar,
        handleBindPhone,
        toBusinessOrder,
        pageNavUrl,
        // gotuMeituanPage,
        goToBindPhone, // 去绑定手机号，领取会员
        toMsg, // 系统消息事件
        goToPage, // 跳转中间导航页面
        goGFShop, // 跳转美团官返店铺
        goGFPj, // 跳转美团官返评价
        goToOrderCheckFun, // 上传凭证事件
        handleUploadOrderNo, // 提交审核
        challengeCountdown, // 挑战赛倒计时
        findcountdown, // 上传凭证倒计时
        findcountdownThere, // 上传订单号倒计时
        cashOutFun, // 提现
        goToOrderPageFun, // 跳转订单页面
        getPhoneNumber, // 微信授权绑定手机号码
        submitTemCode, // 提交邀请码
        updateOrderNo, // 提交订单号
        orderNoCopy, // 复制订单号
        submitOrderNum, // 提交订单号到后台
    }
}